package cn.fzkj.ailangchain4j.ai;

import cn.fzkj.ailangchain4j.tools.QueryTools;
import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.mcp.McpToolProvider;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.service.AiServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ description
 * @ author yaya
 * @ since 2025/10/31
 */
@Configuration
public class CodeHelperServiceFactory {

    @Autowired
    private ChatModel chatModel;
    @Autowired
    private StreamingChatModel streamingChatModel;
    @Autowired
    private ContentRetriever contentRetriever;
//    @Autowired
//    private McpToolProvider mcpToolProvider;

    @Bean
    public CodeHelperService codeHelperService() {
//        return AiServices.create(CodeHelperService.class, chatModel);
//        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);

        return AiServices.builder(CodeHelperService.class)
                .chatModel(chatModel)
                .streamingChatModel(streamingChatModel)
                .tools(new QueryTools()) // tool工具
                .contentRetriever(contentRetriever) // rag
//                .toolProvider(mcpToolProvider) // mcp
                .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
                .build();
    }

}
